<template>
	<view class="address-list">
		<!-- 地址列表 -->
		<u-navbar leftIconSize="34rpx" autoBack :placeholder="true" bgColor="#ffffff">
			<view class="" slot="center">
				<text class="c-000 pf-sc fw-600" style="font-size: 34rpx;">收货地址</text>
			</view>
		</u-navbar>
		<view
			class="set-data-container w-750 b-box d-flex flex-c ali-i-c just-sw bg-fa po-re"
			style="padding:20rpx 24rpx 0;"
			:style="{ height: containerHeight }"
		>
			<view>
				<view
					class="w-100 b-box bg-ff d-flex flex-r ali-i-c just-sw bigItem"
					v-for="(item, index) of CarList"
					:key="item.id"
					style="border-radius: 16rpx;overflow: hidden;height: 208rpx;padding: 34rpx 34rpx 30rpx 36rpx;margin-bottom: 20rpx; "
					@click="goBack(index)"
				>
					<view class="d-flex flex-c ali-i-s just-s b-box item">
						<view class="d-flex felx-r ali-i-c just-s" style="margin-bottom: 8rpx;">
							<u-badge
								v-if="item.is_default == 1"
								:customStyle="{ marginRight: '8rpx', borderRadius: '6rpx' }"
								type="warning "
								bgColor="#ED1D15"
								color="#ffffff"
								shape="horn"
								max="1"
								value="默认"
							></u-badge>

							<text class="pf-sc fw-500 c-000" style="font-size: 34rpx;">{{ item.name }}</text>
							<text class="pf-sc fw-400 c-333" style="font-size: 30rpx;">{{ item.mobile }}</text>
						</view>
						<view>
							<text class="pf-sc fw-400 c-333" style="font-size: 30rpx;">
								{{ item.location }}/{{ item.address }}
							</text>
						</view>
					</view>
					<view
						style="width: 50rpx;height: 50rpx;"
						@click="GoModify(item.id, item.name, item.mobile,item.is_default,item.address)"
					>
						<image :src="require('../static/bj.png')" style="width: 40rpx;height: 40rpx;"></image>
					</view>
				</view>
			</view>
			<!-- btn -->
			<view class="d-flex flex-r ali-i-c just-c b-box w-100" style="margin-bottom: 84rpx;">
				<u-button
					:throttleTime="700"
					@click="AddAddress"
					:customStyle="{
						height: '84rpx',
						width: '602rpx',
						font: '500 32rpx PingFang SC',
						color: '#ffffff',
						borderWidth: '0rpx',
						background: 'linear-gradient(180deg, #4885C5 0%, #3B52A6 100%)',
						borderRadius: '44rpx'
					}"
					shape="square"
					text="新增收货地址"
				></u-button>
			</view>
		</view>
	</view>
</template>

<script>
import { address } from '@/common/api.js';
import { _containerHeight } from '@/utils/GetSys.js';
import Unavbar from '../components/uview-ui/components/u-navbar/u-navbar';
import Ubutton from '../components/uview-ui/components/u-button/u-button';
import uBadge from '../components/uview-ui/components/u-badge/u-badge';

export default {
	components: {
		'u-navbar': Unavbar,
		'u-button': Ubutton,
		'u-badge': uBadge
	},
	data() {
		return {
			containerHeight: '',
			CarList: [],
			type:'',
		};
	},
	methods: {
		//订单页面返回  并且携带地址的id
goBack(id){
	if(this.type==='pay'){
		uni.setStorageSync('addresslist',this.CarList[id])
		uni.navigateBack({
			delta:1
		})
	}else{
		return
	}
},		
		
		//页面加载时获取当前用户的地址列表
		getAddress() {
			let params = {
				token: uni.getStorageSync('usertoken'),
				type: 5
			};
			address(params).then(res => {
				console.log(res.data.data);
				this.CarList = res.data.data;
			});
		},
		GoModify(id, name, phone,is_default,address) {
			//修改地址
			uni.navigateTo({
				url: `/userModelA/userB/EditAddress/EditAddress?id=${id}&name=${name}&phone=${phone}&is_default=${is_default}&address=${address}`
			});
		},
		AddAddress() {
			//新增地址
			uni.navigateTo({
				url: '/userModelA/userB/NewAddress/NewAddress'
			});
		}
	},
	onLoad(e) {
    this.type=e.address;
		this.containerHeight = _containerHeight();
		this.getAddress();
	}
};
</script>

<style lang="scss">
.address-list {
	.item {
		width: 648rpx;
	}
}
</style>
